package com.example.gateway.handler;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

@Slf4j
@Component
public class TestHandler {
	public Mono<ServerResponse> test(ServerRequest serverRequest) {
////		String bodyData = serverRequest.bodyToMono(String.class).toProcessor().peek();
////		System.err.println(bodyData);
//		Mono<String> userMono = serverRequest.bodyToMono(String.class);
//		return userMono.flatMap(user ->
//                ServerResponse.status(HttpStatus.CREATED)
//                        .contentType(MediaType.APPLICATION_JSON)
//                        .body(user,String.class)
//                );

		String uri = serverRequest.uri().toString();
		String method = serverRequest.methodName();
		String contentType = serverRequest.headers().contentType().get().toString();
		String characterSet = serverRequest.headers().acceptCharset().get(0).toString();
		JSONObject bodyData = serverRequest.bodyToMono(JSONObject.class).toProcessor().peek();

		System.out.println("==========toRESTInVerticle Data Check==========");
		System.out.println(uri);
		System.out.println(method);
		System.out.println(contentType);
		System.out.println(characterSet);
		System.out.println(bodyData);
		System.out.println("======toRESTInVerticle Data Check Complete======");
		return Mono.empty();
	}

}
